package com.pmsystem.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pmsystem.pojo.WaterConsume;
import com.pmsystem.service.WaterConsumeService;
import com.pmsystem.util.BeanUtil;

@Controller
public class WaterConsumeController {

	@Autowired
	private WaterConsumeService waterConsumeService;

	/**
	 * 
	 * <p>Title: addWaterConsume</p >  
	 * <p>Description: 录入水费</p >  
	 * @author 泽强
	 * @param waterConsume
	 * @return
	 */
	@RequestMapping(value = "addWaterConsume", method = RequestMethod.POST)
	@ResponseBody
	public Object addWaterConsume(@RequestParam Map<String,Object> map) {
		WaterConsume waterConsume = BeanUtil.parserToBean(BeanUtil.mapToMapWithoutNull(map),WaterConsume.class);
		boolean flag = waterConsumeService.addWaterConsume(waterConsume);
		if (flag) {
			return "success";
		}
		return "error";
	}

	/**
	 * 
	 * <p>Title: findWaterConsume</p >  
	 * <p>Description: 按一定条件查水表</p >  
	 * @author 泽强
	 * @param map
	 * @return
	 */
	@RequestMapping(value = "findWaterConsume", method = RequestMethod.GET)
	@ResponseBody
	public Object findWaterConsume(@RequestParam Map<String,Object> map) {	
		List<WaterConsume> list = waterConsumeService.findWaterConsume(map);
		return list;
	}
	
	/**
	 * 
	 * <p>Title: updateWaterConsume</p >  
	 * <p>Description: 修改</p >  
	 * @author 泽强
	 * @param map
	 * @return
	 */
	@RequestMapping(value = "updateWaterConsume", method = RequestMethod.POST)
	@ResponseBody
	public Object updateWaterConsume(@RequestParam Map<String,Object> map) {
		WaterConsume waterConsume = BeanUtil.parserToBean(BeanUtil.mapToMapWithoutNull(map),WaterConsume.class);
		boolean flag = waterConsumeService.updateWaterConsume(waterConsume);
		if(flag) {
			return "success";
		}
		return "error";
	}

}
